package com.ruoyi.product.controller;


import com.ruoyi.business.domain.product.TbProductCategories;
import com.ruoyi.business.service.product.TbProductCategoriesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品分类表Controller
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/product/categories")
@Api(tags = "商品分类管理接口")
public class TbProductCategoriesController extends BaseController {

    private final TbProductCategoriesService tbProductCategoriesService;

    /**
     * 查询商品分类列表
     */
//    @SaCheckPermission("business:product:categories:list")
    @GetMapping("/list")
    @ApiOperation("查询商品分类列表")
    public TableDataInfo<TbProductCategories> list(TbProductCategories tbProductCategories, PageQuery pageQuery) {
        return tbProductCategoriesService.selectPageList(tbProductCategories,pageQuery);
    }
    @GetMapping(value = "/listAll")
    @ApiOperation("获取商品分类列表不分页")
    public R<List<TbProductCategories>> getInfo(TbProductCategories tbProductCategories) {
        return R.ok(tbProductCategoriesService.selectProductCategorieList(tbProductCategories));
    }
    /**
     * 获取商品分类详细信息
     */
//    @SaCheckPermission("business:product:categories:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取商品分类详情")
    public R<TbProductCategories> getInfo(@PathVariable("id") Long id) {
        return R.ok(tbProductCategoriesService.selectCategoriesById(id));
    }

    /**
     * 新增商品分类
     */
//    @SaCheckPermission("business:product:categories:add")
    @PostMapping
    @ApiOperation("新增商品分类")
    public R<Boolean> add(@RequestBody TbProductCategories tbProductCategories) {
        return R.ok(tbProductCategoriesService.insertCategories(tbProductCategories));
    }

    /**
     * 修改商品分类
     */
//    @SaCheckPermission("business:product:categories:edit")
    @PutMapping
    @ApiOperation("修改商品分类")
    public R<Boolean> edit(@RequestBody TbProductCategories tbProductCategories) {
        return R.ok(tbProductCategoriesService.updateCategories(tbProductCategories));
    }

    /**
     * 删除商品分类
     */
//    @SaCheckPermission("business:product:categories:remove")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除商品分类")
    public R<Boolean> remove(@PathVariable Long[] ids) {
        return R.ok(tbProductCategoriesService.deleteCategoriesByIds(ids));
    }
}
